import authPlugin from "./plugins/auth";
import fastify from "fastify";
import dbPlugin from "./plugins/db";
import envPlugin from "./plugins/env";
import bizPlugin from "./plugins/biz";
import autoload from "@fastify/autoload";
import { resolve } from "path";
import cors from "@fastify/cors";
import cachePlugin from "./plugins/cache";

async function bootstrap() {
  const app = fastify();
  await app
    .register(envPlugin)
    .register(authPlugin)
    .register(dbPlugin)
    .register(cachePlugin)
    .register(bizPlugin)
    .register(cors);

  await app.register(autoload, {
    dir: resolve("dist/modules"),
    options: { prefix: "/api" },
  });
  const { PORT } = app.getEnvs();
  app.listen({ port: PORT, host: "0.0.0.0" });

  console.log(`server listening on port ${PORT}....xxx`);
}

bootstrap();
